package com.acme.bankapp.domain.bank;

public class CheckingAccount extends AbstractAccount {

	static final String MES_NEGATIVE_OVERLAP = "Overlap must be positive or zero value";
	
	private double overdraft;
	
	public CheckingAccount(double balance, double overdraft) throws Exception {
		super(balance);
		if (overdraft < 0)
			throw new Exception(MES_NEGATIVE_OVERLAP);
		this.overdraft = overdraft;
	}

	@Override
	public void withDraw(double x) throws Exception {
		if (x <= 0)
			throw new Exception(MES_NEGATIVE_DEPOSIT);
		else if (balance + overdraft < x) 
			throw new Exception(MES_TOO_SMALL_BALANCE);
		
		balance -= x;
	}

	@Override
	public double maximumAmountToWithdraw() {
		return balance + overdraft;
	}
	
	public double getOverdraft() {
		return overdraft;
	}

	public String toString() {
		return "Account:" + "balance = " + balance + "; overdraft = " + overdraft;
	}
}
